home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C25 / Trash.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.5 KB  |  57 lines

  1. //: C25:Trash.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Base class for Trash recycling examples
  7. #ifndef TRASH_H
  8. #define TRASH_H
  9. #include <iostream>
  10. #include <exception>
  11. #include <vector>
  12. #include <string>
  13.  
  14. class TypedBin; // For a later example
  15. class Visitor; // For a later example
  16.  
  17. class Trash {
  18.   double _weight;
  19.   void operator=(const Trash&);
  20.   Trash(const Trash&);
  21. public:
  22.   Trash(double wt) : _weight(wt) {}
  23.   virtual double value() const = 0;
  24.   double weight() const { return _weight; }
  25.   virtual ~Trash() {}
  26.   class Info {
  27.     std::string _id;
  28.     double _data;
  29.   public:
  30.     Info(std::string ident, double dat)
  31.       : _id(ident), _data(dat) {}
  32.     double data() const { return _data; }
  33.     std::string id() const { return _id; }
  34.     friend std::ostream& operator<<(
  35.       std::ostream& os, const Info& info) {
  36.       return os << info._id << ':' << info._data;
  37.     }
  38.   };
  39. protected:
  40.   // Remainder of class provides support for
  41.   // prototyping:
  42.   static std::vector<Trash*> prototypes;
  43.   friend class TrashPrototypeInit;
  44.   Trash() : _weight(0) {}
  45. public:
  46.   static Trash* factory(const Info& info);
  47.   virtual std::string id() = 0;  // type ident
  48.   virtual Trash* clone(const Info&) = 0;
  49.   // Stubs, inserted for later use:
  50.   virtual bool 
  51.   addToBin(std::vector<TypedBin*>&) { 
  52.     return false; 
  53.   }
  54.   virtual void accept(Visitor&) {};
  55. };
  56. #endif // TRASH_H ///:~
  57.